353C - Find Maximum - CodeForces Solution


implementation math number theory *1600

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using ordered_set= tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll long long int
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define MAX 200005
#define inf 1e9
#define pi acos(-1)
const ll mod=1000000007;
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define ran(a, b) ((((rand() << 15) ^ rand()) % ((b) - (a) + 1)) + (a))


double make_radian(double x){return (x*pi)/180;}
double make_degree(double x){return (x*180)/pi;}
ld distance(ld a,ld b,ld x,ld y) {ld ans=sqrtl(((a-x)*(a-x))+((b-y)*(b-y)));return ans;}
bool point_on_segment(ld a,ld b,ld c,ld d,ld x,ld y){if(distance(a,b,c,d)==distance(a,b,x,y)+distance(x,y,c,d)) return true;else return false;}
ld point_checking(ld a,ld b,ld c,ld d,ld x,ld y){ld ans=(a*(d-y))-(b*(c-x))+((c*y)-(d*x));return ans;/*pos==anti-clock,neg==clockwise,zero==on_line*/}
string dtob(ll n){string s;for(ll i=63;i>=0;i--){if(n&(1LL<<i)) s.pb('1');else s.pb('0');}return s;}
ll btod(string x){ll dec(0);reverse(x.begin(),x.end());for(int i=0;i<x.size();i++)if(x[i]=='1')dec+=pow(2LL,i);return dec;}
void _(){ios_base::sync_with_stdio(false);cin.tie(NULL);}


void solve()
{
    int n;cin>>n;
    vector<int> vc(n),pref(n);
    int total=0;
    for(int i=0;i<n;i++) 
    {
        cin>>vc[i];
        total+=vc[i];
        pref[i]=total;
    }

    string s;cin>>s;
    int ans=0,sum=0;
    for(int i=n-1;i>=0;i--)
    {
        if(s[i]=='1')
        {
            if(i>0) ans=max(ans,sum+pref[i-1]);
            sum+=vc[i];
        }
    }
    ans=max(sum,ans);
    cout<<ans<<endl;
}


int main()
{
    _();
    ll t,tt;
    t=1;
    //cin>>t,tt=t;
    while(t--) solve();
}



Comments

Submit
0 Comments
More Questions

1025D - Recovering BST
439A - Devu the Singer and Churu the Joker
1323A - Even Subset Sum Problem
1095A - Repeating Cipher
630F - Selection of Personnel
630K - Indivisibility
20B - Equation
600B - Queries about less or equal elements
1015A - Points in Segments
1593B - Make it Divisible by 25
680C - Bear and Prime 100
1300A - Non-zero
1475E - Advertising Agency
1345B - Card Constructions
1077B - Disturbed People
653A - Bear and Three Balls
794A - Bank Robbery
157A - Game Outcome
3B - Lorry
1392A - Omkar and Password
489A - SwapSort
932A - Palindromic Supersequence
433A - Kitahara Haruki's Gift
672A - Summer Camp
1277A - Happy Birthday Polycarp
577A - Multiplication Table
817C - Really Big Numbers
1355A - Sequence with Digits
977B - Two-gram
993A - Two Squares